package com.example.word.demo;

import com.example.word.service.impl.TemplateServiceImpl;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.stereotype.Component;

/**
 * @author yuwen
 * @date 2023/5/16
 */
@Component
public class FileValidatorPool {

    private final GenericObjectPool<TemplateServiceImpl> pool;
    public FileValidatorPool() {

        GenericObjectPoolConfig<TemplateServiceImpl> config = new GenericObjectPoolConfig<>();
        config.setMaxTotal(32);
        config.setMinIdle(2);
        config.setMaxIdle(5);
        pool = new GenericObjectPool<>(new FileValidatorFactory(), config);
    }
    public TemplateServiceImpl borrowObject() throws Exception {
        return pool.borrowObject();
    }
    public void returnObject(TemplateServiceImpl validator) {
        pool.returnObject(validator);
    }
}